<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
     $this->display();
   }


  public function checklogin(){
    extract($_POST);
    if(empty($username) || empty($password)){
    	$this->redirect('Login/index');
    }
    $user = D('AdminUser')->where("user_name = '".$username."'")->find();
    if(empty($user)){
      $this->error('用户名不存在!');
    }
    if($user['user_pwd'] == sha1($password)){
      session('user',$user);
    	$this->redirect('Index/index');
    }else{
    	$this->error('密码错误!');
    }
  } 

   //修改密码
    public function news_password(){
     $password =$_POST['password'];
     $password_confirmation =  $_POST['password_confirmation'];
    if($password !=$password_confirmation){
       $this->error('密码不一致!');
    }else{
      $userModel=D('AdminUser');
      $data['user_pwd'] = sha1($password);
      $user = session('user');
      $map['id'] = $user['id'];
      $res = $userModel ->where($map)->save($data);
        if($res != flase){
           session_destroy(); 
           $this->redirect('index');
        }else{
           $this->error('非法操作!');
        }
    }

    }

  public function logout(){
            session_destroy();  //清除服务器的sesion文件
        $this->redirect('Login/index');
  }
}